package Offer.offer2017;

import java.util.Stack;

/**
 * 包含min函数的栈
 * Created by 雷文康 on 2018/1/1.
 */
public class Test21 {
    Stack<Integer> stack1 = new Stack();
    Stack<Integer> stack2 = new Stack();

    public void push(int value){
        stack1.push(value);
        if (stack2.isEmpty()) {
            stack2.push(value);
        } else {
            if (value < stack2.peek()) {
                stack2.push(value);
            } else {
                stack2.push(stack2.peek());
            }
        }
    }
    public int pop(){
        if (stack1.isEmpty()) {
            return -1;
        } else {
            stack2.pop();
            return stack1.pop();
        }
    }

    public int min(){
        return stack2.peek();
    }
}
